﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL.Interfejsi;
using DAL.Entiteti;
using MySql.Data.MySqlClient;

namespace DAL
{
    partial class DAL
    {
        public class KlubDAO : IDaoCrud<Klub>
        {
            #region IDaoCrud<Clan> Members
            protected MySqlCommand c, c1;

            public long create(Klub entity)
            {
                try
                {
                    c = new MySqlCommand("INSERT INTO Klubovi (Ime_Kluba,Grad_Kluba,Logo_Kluba) VALUES ('" + entity.Ime_KLuba + "','" + entity.grad_Kluba + "','" + entity.Logo_Kluba+ "')", con);
                    c.ExecuteNonQuery();
                    return c.LastInsertedId;
                }
                catch (Exception e)
                {
                    throw e;
                }
            }

            public List<Klub> getAll()
            {
                try
                {
                    c = new MySqlCommand("select * from Klubovi", con);
                    MySqlDataReader r = c.ExecuteReader();
                    List<Klub> clanovi = new List<Klub>();
                    while (r.Read())
                    {
                        Klub f = new Klub(r.GetString("Ime_Kluba"), r.GetString("Grad_Kluba"), r.GetString("Logo_Kluba"));
                        f.DajIDKluba = r.GetInt32("IDKlubovi");
                        f.Logo_Kluba = r.GetString("Logo_Kluba");
                        clanovi.Add(f);
                    }
                    return clanovi;
                }
                catch (Exception e)
                {
                    throw e;
                }
            }


            public Klub read(Klub entity)
            {
                throw new NotImplementedException();
            }

            public Klub update(Klub entity)
            {
                c1 = new MySqlCommand("UPDATE Klubovi SET Ime_Kluba= '" + entity.Ime_KLuba + "',Grad_Kluba='" + entity.grad_Kluba + "',Logo_Kluba='" + entity.Logo_Kluba + "' WHERE  IDClana=" + entity.DajIDKluba, con);
                c1.ExecuteNonQuery();
                return entity;
            }

            public void delete(Klub entity)
            {
                c1 = new MySqlCommand("DELETE FROM Klubovi WHERE idKlubovi= "+ entity.DajIDKluba , con);
                c1.ExecuteNonQuery();
                throw new NotImplementedException();
            }

            public Klub getById(double id)
            {
                c = new MySqlCommand("SELECT * from Klubovi WHERE IdKlubovi="+ id, con);
                MySqlDataReader r = c.ExecuteReader();
               
                try {
                        r.Read();
                        Klub cla = new Klub(r.GetString("Ime_Kluba"), r.GetString("Grad_Kluba"), r.GetString("Logo_Kluba"));
                        cla.DajIDKluba = r.GetInt32("IDKlubovi");
                        cla.Logo_Kluba = r.GetString("Logo_Kluba");
                        r.Close();
                        return cla;
                    }
                catch (Exception rrt)
                {
                    r.Close();
                    throw rrt;
                }
            }

            public List<Klub> getByExample(string name)
            {
                throw new NotImplementedException();
            }
            public void deleteCon(double id)
            {
               // c1 = new MySqlCommand(, con);
                c1.ExecuteNonQuery();
            } 
            public List<Klub> GetByClubID(double id)
                {
                    throw new NotImplementedException();
                }
            #endregion
        }
    }
}
